package com.woniuxy.ticketmovie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.ticketmovie.entity.Ticket_type;
import com.woniuxy.ticketmovie.exception.TypeNameExsitException;
import com.woniuxy.ticketmovie.mapper.Ticket_typeMapper;
import com.woniuxy.ticketmovie.service.Ticket_typeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author movie
 * @since 2021-02-21
 */
@Service
public class Ticket_typeServiceImpl extends ServiceImpl<Ticket_typeMapper, Ticket_type> implements Ticket_typeService {

    @Autowired
    private Ticket_typeMapper mapper;

    @Transactional(propagation=Propagation.REQUIRED)
    @Override
    public void add(Ticket_type type){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("name",type.getName());

        if (mapper.selectCount(queryWrapper)==0){
            mapper.insert(type);
        }else {
            throw new TypeNameExsitException("");
        }
    }

    //修改要求，首先不能修改的名称和别人重名
    //其次修改名称和原名称一样可以不用修改


}








